from selenium.webdriver.common.by import By

from pom.base import BaseDriver

class AccountLogin(BaseDriver):

    _login_link = By.XPATH, '//span[text()="用户中心账号"]'
    _first_login_btn = By.XPATH, '//span[text()="用户中心登录"]/..'
    _account_pass_login = By.XPATH, '//a[text()="账号密码登录"]'
    _username = By.XPATH, '//input[@placeholder="邮箱"]'
    # _username = By.XPATH, '//input[@placeholder="邮箱/账号ID"]'
    _pass = By.XPATH, '//input[@placeholder="密码"]'
    _login_btn = By.XPATH, '//span[text()="授权并登录"]/..'
    _fail_alert = By.XPATH, '//div[@role="alert"]/p'

    def __init__(self, driver):
        super(AccountLogin, self).__init__(driver)

    @property
    def login_link(self):
        return self.find_ele(*self._login_link)

    @property
    def first_login_btn(self):
        ele = self.find_ele(*self._first_login_btn)
        self.logger.info("找到 [用户中心登录] 按钮")
        return ele


    @property
    def account_pass_login(self):
        ele = self.find_ele(*self._account_pass_login)
        self.logger.info("找到 [账号密码登录] 元素")
        return ele

    @property
    def username(self):
        ele = self.find_ele(*self._username)
        self.logger.info("找到 [用户名] 输入框")
        return ele


    @property
    def passwd(self):
        ele = self.find_ele(*self._pass)
        self.logger.info("找到 [密码] 输入框")
        return ele

    @property
    def login_btn(self):
        ele = self.find_ele(*self._login_btn)
        self.logger.info("找到 [登录] 按钮")
        return ele

    @property
    def fail_alert(self):
        ele = self.find_ele(*self._fail_alert)
        self.logger.info("登录失败提示框")
        return ele